var t, e, a = "", o = "", i = "", n = 20, l = null;

Page({
    data: {
        imageWidth: 0,
        imageHeight: 0
    },
    onLoad: function(e) {
        a = e.photoPath, o = e.text, i = e.color, t = e.alpha, this.mark()
    },
    mark: function() {
        n = o.length > 5 ? 20 : 30, e = o.length * n;
        var l = this, s = wx.createCanvasContext("myCanvas");
        wx.getImageInfo({
            src: a,
            success: function(a) {
                var n = a.width, h = a.height;
                console.log("imgWidth=" + n), console.log("imgHeight=" + h);
                var c = wx.getSystemInfoSync().windowWidth;
                console.log("screenWidth=" + c);
                var r = c, g = h / n * r;
                console.log("canvasWidth=" + r), console.log("canvasHeight=" + g), l.setData({
                    imageWidth: r,
                    imageHeight: g
                }), s.drawImage(a.path, 0, 0, r, g), s.rotate(30 * Math.PI / 180);
                for (var d = 1; d < 30; d++) {
                    s.beginPath(), s.setGlobalAlpha(t), s.setFontSize(18), s.setFillStyle(i), s.fillText(o, 0, 80 * d);
                    for (var f = 1; f < 30; f++) s.beginPath(), s.setGlobalAlpha(t), s.setFontSize(18), 
                    s.setFillStyle(i), s.fillText(o, e * f, 80 * d);
                }
                for (var w = 0; w < 30; w++) {
                    s.beginPath(), s.setGlobalAlpha(t), s.setFontSize(18), s.setFillStyle(i), s.fillText(o, 0, -80 * w);
                    for (var m = 1; m < 30; m++) s.beginPath(), s.setGlobalAlpha(t), s.setFontSize(18), 
                    s.setFillStyle(i), s.fillText(o, e * m, -80 * w);
                }
                s.draw(!1, function() {
                    wx.canvasToTempFilePath({
                        x: 0,
                        y: 0,
                        width: n,
                        height: h,
                        destWidth: n,
                        destHeight: h,
                        canvasId: "myCanvas",
                        success: function(t) {
                            wx.hideLoading(), l.addMarkPhotoPath = t.tempFilePath;
                        }
                    });
                });
            }
        });
    },
    saveTap: function() {
      var that = this;
      wx.showLoading({
          title: "保存中",
          duration: 2000 // 设置加载动画持续时间为2秒
      });
      wx.showModal({
        content: "保存成功，请在相册中查看",
        confirmText: "知道了",
        showCancel: false
    });
      wx.saveImageToPhotosAlbum({
          filePath: that.addMarkPhotoPath,
          success: function(t) {
              wx.hideLoading(); // 隐藏加载动画
              wx.showModal({
                  content: "保存成功，请在相册中查看",
                  confirmText: "知道了",
                  showCancel: false
              });
          }
      });
  }
  
});
